package org.xnsg.app.model;

import com.eova.common.base.BaseModel;



public class pt_log extends BaseModel<pt_log> {

	private static final long serialVersionUID = 1064291771401662738L;


	/*/
SQL> desc pt_log
Name    Type          Nullable Default Comments
------- ------------- -------- ------- --------
ID      NUMBER(10)
USER_ID NUMBER(10)
TYPE    NUMBER(10)
IP      VARCHAR2(255)
INFO    VARCHAR2(500) Y
HTIME   DATE          Y

SQL>
	 */
	public static final pt_log dao = new pt_log();
	public String className = "com.oss.model.pt_log";

	public String findLastLoginTimeByID(int id){
		// 找到上一次的登录时间
		String method = "findLastLoginTimeByID";
		String prompt = className + "." + method + ">";
		System.out.println(prompt + "start ...");

		String sql = "select to_char(max(t1.htime), 'yyyy-mm-dd hh24:mi:ss') htime from pt_log t1 where t1.user_id = ? and t1.info like 'system_login%'";
		pt_log result = null;
		String htime = "";
		try {
			result = this.findFirst(sql, id);;
			htime = result.getStr("htime");
			System.out.println(prompt + "htime=[" + htime + "]");
		} catch ( Exception e) {
			System.out.println(prompt + "sql=[" + sql + "]");
			System.out.println(prompt + e);
	    }

		System.out.println(prompt + "end.");

		return htime;
	}

	public String findLastLoginIPByID(int id){
		// 找到上一次的登录地址
		String method = "findLoginTimeByID";
		String prompt = className + "." + method + ">";
		System.out.println(prompt + "start ...");

		String sql = "select * from (select t1.ip from pt_log t1 where t1.user_id = ? and t1.info like 'system_login%' order by htime desc) where rownum<2";
		pt_log result = null;
		String LastLoginIP = "";
		try {
			result = this.findFirst(sql, id);;
			LastLoginIP = result.getStr("ip");
			System.out.println(prompt + "LastLoginIP=[" + LastLoginIP + "]");
		} catch ( Exception e) {
			System.out.println(prompt + "sql=[" + sql + "]");
			System.out.println(prompt + e);
	    }

		System.out.println(prompt + "end.");

		return LastLoginIP;

	}

	public String findLoginTimeByID(int id){
		// 找到总登录次数

		String method = "findLoginTimeByID";
		String prompt = className + "." + method + ">";
		System.out.println(prompt + "start ...");

		String sql = "select count(*) htime from pt_log t1 where t1.user_id = ? and t1.info like 'system_login%'";
		pt_log result = null;
		String HTime = "";
		try {
			result = this.findFirst(sql, id);;
			HTime = result.getInt("htime").toString();
			System.out.println(prompt + "LoginTime=[" + HTime + "]");
		} catch ( Exception e) {
			System.out.println(prompt + "sql=[" + sql + "]");
			System.out.println(prompt + e);
	    }

		System.out.println(prompt + "end.");

		return HTime;
	}

}
